<template>
	<view class="group">
		<view class="groupItem" v-show="actionLabel!==''" @tap="action(status)">{{actionLabel}}</view>
		<view class="groupItem" v-show="status==0" @tap="needLoginToNav('/pages/save?id='+id)">编辑</view>
		<view class="groupItem" style="background:#004ea2" @tap="needLoginToNav('/pages/action/detail?id='+this.id)">
			查看详情</view>
	</view>
</template>

<script>
	import helper from '../../common/helper';
	import api from '@/api.js';
	export default {
		name: "actionGroup",
		mixins: [helper],
		props: ['status', 'id'],
		data() {
			return {
				actionLabel: '',
			};
		},
		watch: {
			status(newVal, oldVal) {
				this.change(this.status);
			}
		},
		methods: {
			ruku(id) {
				api.doRequest("post", "valve/ruku", {
					id: this.id
				}).then(res => {
					if (res.statusCode == 200) {
						uni.showToast({
							title: "操作成功",
							icon: "none"
						})
						var that = this;
						setTimeout(function() {
							that.$emit('refresh', true);
						}, 1000)
					} else {
						uni.showToast({
							title: "服务故障",
							icon: "none"
						})
					}
				})
			},
			chuku(id) {
				api.doRequest("post", "valve/chuku", {
					id: this.id
				}).then(res => {
					
					if (res.statusCode == 200) {
						uni.showToast({
							title: "操作成功",
							icon: "none"
						})
						var that = this;
						setTimeout(function() {
							that.$emit('refresh', true);
						}, 1000)

					} else {
						uni.showToast({
							title: "服务故障",
							icon: "none"
						})
					}
				})
			},
			change(e) {
				switch (e) {
					case 0:
						this.actionLabel = '拆修';
						break;
					case 1:
						this.actionLabel = '';
						break;
					case 2:
						this.actionLabel = "维修";
						break;
					case 3:
						this.actionLabel = '试压';
						break;
					case 4:
						this.actionLabel = '喷漆';
						break;
					case 5:
						this.actionLabel = '喷漆并入库';
						break;
					case 6:
						this.actionLabel = '出库发货';
						break;
					case 7:
						this.actionLabel = '';
						break;
					case 8:
						this.actionLabel = '';
						break;
					default:
						this.statusText = '';
						break;
				}
			},
			action(status) {
				let id = this.id;
				switch (status) {
					case 0:
						uni.navigateTo({
							url: '/pages/action/chai?id=' + this.id
						});
						break;
					case 2:
						uni.navigateTo({
							url: "/pages/action/xiu?id=" + this.id
						});
						break;
					case 3:
						uni.navigateTo({
							url: "/pages/action/shiya?id=" + this.id
						});
						break;
					case 4:
						uni.navigateTo({
							url: "/pages/action/penqi?id=" + this.id
						});
						break;
					case 5:
						uni.navigateTo({
							url: "/pages/action/penqi?id=" + this.id
						});
						
						break;
					case 6:
						this.chuku(this.id);
						
						break;
					default:
						uni.navigateTo({
							url: "/pages/action/chai?id=" + this.id
						})
						break;
				}

			}
		},

		mounted() {
			this.change(this.status);
		}
	}
</script>

<style>
	.group {
		width: 710upx;
		border-radius: 0 0 20upx 20upx;
		display: flex;
		padding: 20upx 0;
	}

	.groupItem {
		width: 160upx;
		display: flex;
		border-radius: 10upx;
		align-items: center;
		color: #fff;
		justify-content: center;
		background: #e61022;
		margin-left: 20upx;
		font-size: 12px;
		height: 50upx;
	}
</style>